package com.iot08.common.entity.app;

import com.iot08.common.entity.admin.Channel;
import lombok.Data;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.io.Serializable;
import java.util.Date;
import java.util.Locale;
import java.util.Map;

/**
 * @version 1.0
 * @Description: 设备实体
 * @time: 2020/8/26 15:29
 * @author: Rock
 */
@Data
@Document("device")
public class Device implements Serializable {
    private static final long serialVersionUID = 1L;

    @Field("_id")
    private String id;

    private String name;

    private String sex;

    private String birthday;

    private Integer height = 100;

    private Integer weight = 20;
    /**
     * 今日步数
     */
    private Integer step;
    private Integer targetStep;
    /**
     * 头像文件名 xxx.jpg
     */
    private String image;

    /**
     * 设备电话号码
     */
    private String phone;

    private Map<String, Object> loc;

    private Map<String, Object> nowloc;
    /**
     * 电量百分比
     * 没传默认100
     */
    private Integer battery = 100;

    /**
     * 设备导入系统时间
     */
    private Date ImportTime;

    /**
     * 设备首次登录系统时间
     */
    private Date firstLoginTime;

    private Double firstLoginTimeStamp;
    /**
     * 设备最后一次登录系统时间
     */
    private Date lastLoginTime;
    /**
     * 设备代理商
     */
    private Long agent;
    /**
     * 设备型号id
     */
    @Field("model_id")
    private String modelId;
    /**
     * 型号名称
     */
    private String model;
    /**
     * 设备功能（C0:微聊、S0:、P0:拍照、V0SW:声网、V0JF:菊风、W0:WIFI密码设置功能）
     */
    private String modules;
    /**
     * 1=手动导入
     */
    private Integer manualImport;

    //厂商
    @Field("v")
    private Integer vendor;

    private String devModel;

    /**
     * 设备的型号
     */
    private String version = "";

    //默认中文 eg:zh_CN 或 zh-Hans-CN 或 zh
    private String language = "zh";

    private Locale locale;

    public Locale getLocale(){
        if(language.contains("_")){
            String[] split = language.split("_");
            // 国家，地区
            locale = new Locale(split[0], split[split.length-1]);
        }else if(language.contains("-")){
            String[] split = language.split("-");
            // 国家，地区
            locale = new Locale(split[0], split[split.length-1]);
        }else{
            // 可能是类似 zh 等
            locale = new Locale(language);
        }
        return locale;
    }


    @Field("contact_upper_limit")
    private Integer contactUpperLimit;

    @Field("telecom_status")
    private Integer telecomStatus;

    @Field("production_batch")
    private String productionBatch;

    @Field("video_endtime")
    private Integer videoEndtime;

    @Field("video_permanent")
    private Integer videoPermanent;

    @Field("old_video_permanent")
    private Integer oldVideoPermanent;

    @Field("video_limit_status")
    private Integer videoLimitstatus;

    private Integer cancelVideoAutoHangUp;

    /**
     * 是否有视频 553 机制的限制 (每次只能拨打5分钟 拨打满10分钟时, 视频之间的休息间隔需要休息满3分钟,不然会触发限制)
     * 由于之前是由设备
     */
    private Integer JFvideolimit553;

    private Integer canCheckPosition;

    private Integer isWatchCustomFunction;

    private String watchCustomFunction;

    private String videoModelId;

    private Integer ppmfmodules;

    private Integer telecom;

    private Integer dataFlow;

    private Integer costFlow;

//    private Integer opdialswitch;
    // 拨号盘状态 存在此状态 才有此功能, 默认是开启 1
    private Integer dialSwitch;

    private Integer opfind;

    //小红花
    private Integer flower = 0;

    //导航
    private Integer navigationmodules;
    // SOS短信报警开关状态
    private Integer SOS_AL = 1;
    // 低电报警开关状态
    private Integer LOWBAT_AL = 1;

    private String watchStoreChannelId;

    private String watchStoreChannelName;

    private String token;
    private String ttime;

    private String creator;

    private Integer lastBattery;

    @Field("g")
    private Map<String, Map<String, Object>> chatGroupMap;

    /**
     * 绑定手表的用户列表
     */
    @Field("u")
    private Map<String, Map<String, Object>> userMap;

    /**
     * 自动接通功能状态 (设备的自动配置有 ASO配置时才有)
     */
    private Integer asoStatus = 0;
    /**
     * 代收短信功能状态 (设备的自动配置有 CMSG配置时才有)
     */
    private Integer cmsgStatus = 0;

    /**
     * 久坐提醒状态 1:打开, 0:关闭 (自动配置有SR才有) (上午/下午有一个打开就是开的)
     */
    private Integer sedentaryStatus = 0;

    /**
     * 设备挂失状态 1:打开, 0:关闭 (自动配置有LOSSDEV才有)
     */
    private Integer lossDevStatus = 0;

//    @Field("uuids")
//    private Map<String, Map<String, Object>> uuidsMap;

//    @Field("checked_uuids")
//    private Map<String, Map<String, Object>> checkedUuidsMap;

    @Field("checked_openids")
    private Map<String, Map<String, Object>> checkedOpenidsMap;

    private String grade;

    private Integer volume;

    //定位间隔模式  -1 0 1 2 3  (关闭/两小时/一个小时/半个小时/手动模式)
    private Integer locMode;

    //定位间隔分钟数 0~60的分钟
    private Integer locModeMin;

    private Integer rejectStrange;

    @Field("curr_level")
    private Integer currLevel = 0;
    @Field("max_level")
    private Integer maxLevel = 0;

    private String platform;

    private Map<String, Map<String, Object>> wifis;

    @Field("c")
    private Map<String, Map<String, Object>> contactMap;

    @Field("r")
    private Map<String, Map<String, Object>> railMap;

    @Field("channel_area_id")
    private String channelAreaId;

    @Field("network_operator")
    private Integer networkOperator;

    @Field("navigation")
    private Map<String, Map<String, Object>> navigationMap;

    @Field("disBan")
    private Map<String, Map<String, Object>> disBanMap;

    private String iccid;

    @Field("video_id")
    private String videoId;

    @Field("newVideo_id")
    private String newVideoId;

    @Field("video_type")
    private Integer videoType;

    /**
     * 预留电量省电模式的开关状态(当自定义配置上传RSE是才有)
     */
    private Integer powerModelSW = 0;

    private Integer powerModel;

    private Integer isIOTCard = 0;

    @Field("huanxin_username")
    private String huanxinUsername;
    @Field("huanxin_password")
    private String huanxinPassword;

    private Integer devOrientGroup;

    @Field("s")
    private Map<String, Map<String, Object>> sos;

    @Field("va")
    private Map<String, Map<String, Object>> voiceAlarm;

    //碰碰好友列表
    @Field("pf")
    private Map<String, Map<String, Object>> ppFriends;

    @Transient
    private Channel channel;

    // 需要接入DMP平台的设备才有的字段: DMP 账户ID (对应 dmp_account 表)
    private String dmpAccountId;

    // 需要接入(腾讯智联)设备微信的设备才有的字段 设备的签名
    private String deviceSignature;

    /**
     * 是否打开了自动更新状态 1:打开 0:关闭 (自动配置有OTA_*才有)
     */
    private Integer OTAStatus = 0;

    /**
     * 是否允许使用移动数据下载安装包状态 1:允许 0:不允 (自动配置有OTA_*才有)
     */
    private Integer useMobileData = 0;

    /**
     * 上传的单词总数
     */
    private Integer updateWordCount = 0;

    //夜间省电模式状态
    private Integer powerSavingModeStatus = 0;

    //智能闹钟开关（0：关，1：开）
    private Integer smartAlarmStatus = 1;

    //智能上课禁用开关（0：关，1：开）
    private Integer smartDisturbBanStatus = 1;

    //是否为新版微聊协议的设备（0：否，1：是）
    private Integer isNewWechatProtocol = 0;

    /**
     * 视频标识
     * 用于标识单聊视频相关功能
     */
    @Field("video_identify")
    private String videoIdentify;

    /**
     * 群聊视频标识
     * 用于标识群聊视频相关功能
     */
    @Field("group_video_identify")
    private String groupVideoIdentify;
}
